import fetch from 'utils/fetch'
import md5 from 'js-md5'

export default {
  global () {
    return fetch({url: '/global'})
  },
  login (data, options) {
    data = Object.assign({}, data)
    data.password = md5(data.password)
    return fetch({
      url: '/guest/login',
      method: 'POST',
      options,
      data
    })
  },
  // ----注册接口
  // 检查账号是否存在
  checkAccount (params) {
    return fetch({
      url: '/guest/checkAccount',
      params
    })
  },
  // 生成图片验证码
  generateValidateCode (params) {
    return fetch({
      url: '/guest/generateImgValidateCode',
      params
    })
  },
  // 注册
  checkRegister (data, options) {
    return fetch({
      url: '/guest/register',
      method: 'POST',
      options,
      data
    })
  },
  // 获取手机邮箱验证码
  sendValidateCode (params) {
    return fetch({
      url: '/guest/sendValidateCode',
      params
    })
  },
  // 校验图片验证码
  checkImgCode (params) {
    return fetch({
      url: '/guest/checkImgValidateCode',
      params
    })
  },
  // 校验手机验证码
  checkValidateCode (params) {
    return fetch({
      url: '/guest/checkSmsValidateCode',
      params
    })
  },
  // 校验昵称是否存在
  checkNickname (params) {
    return fetch({
      url: '/guest/checkNickname',
      params
    })
  },
  // 设置昵称和密码
  setPasswordAndNickname (data, options) {
    data = Object.assign({}, data)
    data.password = md5(data.password)
    return fetch({
      url: '/guest/register/setPasswordAndNickname',
      method: 'POST',
      options,
      data
    })
  },
  // 邮箱注册绑定手机
  bindPhone (data, options) {
    return fetch({
      url: '/register/bindPhone',
      method: 'POST',
      options,
      data
    })
  },
  // 账号激活验证
  verification (params) {
    return fetch({
      url: '/guest/activate/verification',
      params
    })
  },
  // 账号激活用户信息
  activate (data, options) {
    data = Object.assign({}, data)
    data.loginPwd = md5(data.loginPwd)
    return fetch({
      url: '/guest/activate',
      method: 'POST',
      options,
      data
    })
  },
  // 用户登出
  userExit () {
    return fetch({
      url: '/user/exit'
    })
  },
  // 忘记密码
  forgrtPassword (data) {
    return fetch({
      url: '/guest/forget/password',
      method: 'POST',
      data
    })
  },
  // 重置密码
  resetPassword (data) {
    data = Object.assign({}, data)
    data.password = md5(data.password)
    return fetch({
      url: '/guest/resetPassword',
      method: 'POST',
      data
    })
  }
}
